import request from '../../../apis/axios'

// 获取表格数据
export function getTableData(path, data, id,apiHeader) {
  let other
  if (!id || id === '') {
    other = ''
  } else {
    other = id
  }
  const config = {
    url: path + other,
    method: 'post',
    data
  }
  if(apiHeader){
    config.headers = apiHeader
  }
  return request(config)
}
// 获取分页模式业务请求
export function pageTableData(path, data, id,apiHeader) {
  let other
  if (!id || id === '') {
    other = ''
  } else {
    other = id
  }
  const config = {
    url: path + other,
    method: 'post',
    data
  }
  if(apiHeader){
    config.headers = apiHeader
  }
  return request(config)
}
/**
 * 获取数据字典
 * @param {string} dictTypeCode 数据字典类型编码
 * @param {string} appCode 应用编码
 * @param {string} domainCode 业务域编码
 * */
export function getDictByType({ dictTypeCode, appCode, domainCode }) {
  return request({
    url: `/data-dict/api/v2/dictionary/${dictTypeCode}`,
    method: 'get',
    params: { appCode, domainCode }
  })
}

/**
 * 获取收藏的查询条件
 * @param {string} menuCode 菜单编码
 * @param {Number} tabIndex 表格索引
 * */ 
export function getCollectList(menuCode,tabIndex) {
  return request({
    url: `/ucenter/api/v2/userQueryCondition/collects?menuCode=${menuCode}&tabIndex=${tabIndex}`,
    method: 'get'
  })
}

/**
 * 获取当前用户权限下的按钮
 * @param {string} menuCode 菜单编码
 * @param {string} buttonGroupCode 按钮组编码
 * */ 
export function getBtns({menuCode,buttonGroupCode,url='/ucenter/api/v2/button/currentUser'}) {
  return request({
    url,
    method: 'get',
    params: {menuCode,buttonGroupCode}
  })
}

/**
 * 获取收藏的查询条件
 * @param {string} menuCode 菜单编码
 * @param {Number} tabIndex 表格索引
 * */ 
export function chooseSearchData(data, menuCode,tabIndex) {
  return request({
    url: `/ucenter/api/v2/userQueryCondition/collect/page?menuCode=${menuCode}&tabIndex=${tabIndex}`,
    method: 'post',
    data
  })
}


/**
 * 收藏/取消收藏查询条件
 * @param {string} queryId  查询条件ID
 * @param {Number} isCollect isCollect 收藏 1， 取消收藏 0
 */
export function queryConditions(queryId, isCollect) {
  return request({
    url: `/ucenter/api/v2/userQueryCondition/${queryId}/${isCollect?'collect':'uncollect'}`,
    method: 'post'
  })
}

/**
 * 删除查询条件
 * @param {string} queryId  查询条件ID
 */
export function deleteConditions(queryId) {
  return request({
    url: `/ucenter/api/v2/userQueryCondition/${queryId}`,
    method: 'delete'
  })
}

// 查询---远程搜索
export function remoteSearch(path, params) {
  return request({
    url: path,
    method: 'get',
    params
  })
}

// 新增表格设置
export function addTableConfig(data) {
  return request({
    url: '/ucenter/api/v2/userGridSetting',
    method: 'post',
    data
  })
}

// 保存表格设置
export function saveTableConfig(data, id) {
  return request({
    url: `/ucenter/api/v2/userGridSetting/${id}`,
    method: 'put',
    data
  })
}
// 清空表格设置
export function deletTableConfig(settingId) {
  return request({
    url: `/ucenter/api/v2/userGridSetting/${settingId}`,
    method: 'delete'
  })
}

/**
 * 获取表格设置
 * @param {string} menuCode 菜单编码
 * @param {Number} tabIndex 表格索引
 * */ 
export function getTableConfig({menuCode,tabIndex}) {
  return request({
    url: `/ucenter/api/v2/userGridSetting/currentUser?menuCode=${menuCode}&tabIndex=${tabIndex}`,
    method: 'get'
  })
}

// 获取行内编辑远程数据
export function getTableEditData(method = 'get', path, params) {
  let data = method.toLocaleLowerCase() === 'get' ? 'params' : 'data'
  return request({
    url: path,
    method: method,
    [data]: params
  })
}